﻿using BielskoNoca.DAL.Abstract;
using BielskoNoca.DAL.Models;
using System;
using System.Collections.Generic;
using System.Linq;

namespace BielskoNoca.DAL.Concrete
{
    public class CategoryRepository : ICategoryRepository
    {
        private BielskoNocaDataEntities context;
            //= new BielskoNocaDataEntities();

        public CategoryRepository(BielskoNocaDataEntities context)
        {
            this.context = context;
        }

        public IQueryable<Models.Category> Query
        {
            get { return this.context.Categories; }
        }

        public Models.Category GetFirstOrDefault(System.Linq.Expressions.Expression<Func<Models.Category, bool>> whereCondition)
        {
            return this.Query.FirstOrDefault(whereCondition);
        }

        public int Add(Models.Category entity)
        {
            Category tEntity = this.context.Categories.Add(entity);
            this.context.SaveChanges();

            return tEntity.Id;
        }

        public void Delete(Models.Category entity)
        {
            throw new NotImplementedException();
        }

        public void Attach(Models.Category entity)
        {
            throw new NotImplementedException();
        }

        public IList<Models.Category> GetAll(System.Linq.Expressions.Expression<Func<Models.Category, bool>> whereCondition)
        {
            throw new NotImplementedException();
        }

        public IList<Models.Category> GetAll()
        {
            return this.Query.ToList();
        }

        public long Count(System.Linq.Expressions.Expression<Func<Models.Category, bool>> whereCondition)
        {
            throw new NotImplementedException();
        }

        public long Count()
        {
            throw new NotImplementedException();
        }

        public Category GetById(int id)
        {
            return this.GetFirstOrDefault(cat => cat.Id == id);
        }
    }
}